package common.utils;

import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.widget.Button;
import android.widget.TextView;

import com.enqualcomm.kids.R;

/**
 * Created by Administrator on 2016/9/23.
 */

public class MyFrontUtil {
    /**
     * 名字在最前面
     * 名字+的+标题名称
     */
    public static void initTextViewText(Context context, TextView tv, String watchName, String titleName) {
        if (watchName == null || titleName == null || tv == null) {
            return;
        }
        String watch_name_color = context.getString(R.string.watch_name_color);
        ForegroundColorSpan span = new ForegroundColorSpan(Color.parseColor(watch_name_color));
        SpannableString titlename = new SpannableString(watchName + context.getString(R.string.de) + titleName);
        titlename.setSpan(span, 0, watchName.length(), Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        tv.setText(titlename);
    }

    /**
     * 有起始和终止位置的设置字体颜色
     * */
    public static void initTextViewText(Context context, TextView tv, String watchName, String beginText, String endText, int bIndex, int eIndex) {
        if (watchName == null || beginText == null || tv == null || endText == null) {
            return;
        }
        String watch_name_color = context.getString(R.string.watch_name_color);
        ForegroundColorSpan span = new ForegroundColorSpan(Color.parseColor(watch_name_color));
        SpannableString titlename = new SpannableString(beginText + watchName  + endText);
        titlename.setSpan(span, bIndex, eIndex, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        tv.setText(titlename);
    }
    /**
     * 有起始和终止位置的设置字体颜色
     * */
    public static void initTextViewText(Context context, Button button, String watchName, String beginText, String endText, int bIndex, int eIndex) {
        if (watchName == null || beginText == null || button == null || endText == null) {
            return;
        }
        String watch_name_color = context.getString(R.string.watch_name_color);
        ForegroundColorSpan span = new ForegroundColorSpan(Color.parseColor(watch_name_color));
        SpannableString titlename = new SpannableString(beginText + watchName  + endText);
        titlename.setSpan(span, bIndex, eIndex, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
        button.setText(titlename);
    }
}
